package com.jfee.dds.rest;

import com.jfee.dds.mapper.UserMapper;
import com.jfee.dds.model.User;
import com.jfee.dds.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户数据访问接口。
 *
 * @author sf.xiong
 * @version 2019-05-31
 */
@RestController
@RequestMapping(value = "/api/user")
public class UserController extends BaseController {

    @Autowired
    private UserMapper userMapper;

    /**
     * 查询项目中所有用户信息
     *
     * @return 用户列表
     */
    @GetMapping(value = "/v1/list")
    public Result<List<User>> queryUser() {
        Result<List<User>> result = new Result<>();
        result.setData(userMapper.getUsers());
        return result;
    }

    @PostMapping(value = "/v1/save")
    public Result<Integer> saveUser(User user) {
        Result<Integer> result = new Result<>();
        result.setData(userMapper.insert(user));
        return result;
    }
}
